﻿using System;
using Autodesk.AutoCAD.Geometry;

namespace AutoCAD_CSharp_plug_in3.Chap03
{
    public static class AngleHelper
    {
        // 角度转弧度
        public static double DegreesToRadians(double degrees)
        {
            return degrees * Math.PI / 180.0;
        }

        // 弧度转角度
        public static double RadiansToDegrees(double radians)
        {
            return radians * 180.0 / Math.PI;
        }

        // 标准化角度到 [0, 360) 度
        public static double NormalizeDegrees(double degrees)
        {
            degrees = degrees % 360;
            return degrees < 0 ? degrees + 360 : degrees;
        }

        // 标准化弧度到 [0, 2π) 弧度
        public static double NormalizeRadians(double radians)
        {
            radians = radians % (2 * Math.PI);
            return radians < 0 ? radians + 2 * Math.PI : radians;
        }
        
        /// <summary>
        /// 计算从起点到终点的方向角度（弧度）
        /// </summary>
        /// <param name="startPoint">起点</param>
        /// <param name="endPoint">终点</param>
        /// <returns>方向角度（弧度）</returns>
        public static double CalculateDirectionAngle(Point3d startPoint, Point3d endPoint)
        {
            return Math.Atan2(endPoint.Y - startPoint.Y, endPoint.X - startPoint.X);
        }
    }
}